package kr.saeildamil.androidStudy_second.ani;

import kr.saeildamil.androidStudy_second.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class AnimationSetTest extends Activity {
	ImageView mAnimTarget;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_animset);

		mAnimTarget = (ImageView) findViewById(R.id.animtarget);
	}

	public void mOnClick(View v) {
		AnimationSet ani = null;
		switch (v.getId()) {
		case R.id.btnstart:
			ani = new AnimationSet(true);
			ani.setInterpolator(new LinearInterpolator());

			TranslateAnimation trans = new TranslateAnimation(
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, 1,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, 0);
			trans.setDuration(3000);
			ani.addAnimation(trans);

			AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
			alphaAnimation.setDuration(300);
			alphaAnimation.setStartOffset(500);
			alphaAnimation.setRepeatCount(4);
			alphaAnimation.setRepeatMode(Animation.REVERSE);
			ani.addAnimation(alphaAnimation);
			break;
		}
		mAnimTarget.startAnimation(ani);
	}
}
